package com.grj.park.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.grj.park.common.R;
import com.grj.park.domain.Investors;
import com.grj.park.domain.Invitations;
import com.grj.park.service.InvestorsService;
import com.grj.park.service.InvitationsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("invitations")
public class InvitationsController {

    private final InvitationsService invitationsService;

    @GetMapping
    public R<List<Invitations>> getInvestors(){
        return R.ok(invitationsService.list());
    }

    @PostMapping
    public R<?> saveInvestors(@RequestBody Invitations invitations){
        LambdaQueryWrapper<Invitations> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Invitations::getInvitedUsers, invitations.getInvitedUsers());
        Invitations one = invitationsService.getOne(queryWrapper);
        if (one != null){
            return R.fail("邀请名字已存在");
        }
        invitationsService.save(invitations);
        return R.okMsg("添加邀请成功");
    }
}
